package com.ecfront.dao.impl;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.ecfront.dao.MessageDAO;
import com.ecfront.pojo.Message;


/**
 * @version 1.0
 * @author www.ecfrom.com
 */

public class MessageDAOImpl extends HibernateDaoSupport implements MessageDAO {

	protected void initDao() {}


	public void save(Message transientInstance) {
		getHibernateTemplate().saveOrUpdate(transientInstance);
	}

	public void delete(Message persistentInstance) {
		getHibernateTemplate().delete(persistentInstance);
	}


	public Message findById(java.lang.Integer id) {
		Message instance = (Message) getHibernateTemplate().get(
					"com.ecfront.pojo.Message", id);
		return instance;
	}


	public List findByProperty(String propertyName, Object value) {
		String queryString = "from Message as model where model."
					+ propertyName + "= ?";
		return getHibernateTemplate().find(queryString, value);
	}


	public List findByMcontent(Object mcontent) {
		return findByProperty(MCONTENT, mcontent);
	}


	public List findByMtype(Object mtype) {
		return findByProperty(MTYPE, mtype);
	}


	public List findAll() {
		String queryString = "from Message";
		return getHibernateTemplate().find(queryString);
	}

	public static MessageDAO getFromApplicationContext(ApplicationContext ctx) {
		return (MessageDAO) ctx.getBean("MessageDAO");
	}
}